package com.etoak.service;

import com.etoak.bean.Email;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

/**
 * @program: activemq-consumer-email
 * @description:
 * @author: 管浩杰
 * @create: 2021-03-17 15:26
 **/

@Service
public class EmailService {
    /* 邮件发送对象 */
    @Autowired
    private JavaMailSenderImpl sender;

    /* 线程池 */
    @Autowired
    private ThreadPoolTaskExecutor executor;

    public void send(Email email){
        /* 封装简易邮件信息 */
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom("luxilejn@163.com");
        simpleMailMessage.setTo(email.getReceiver());
        simpleMailMessage.setSubject(email.getSubject());
        simpleMailMessage.setText(email.getContent());
        /* 抄送 */
        simpleMailMessage.setCc("874735833@qq.com");

        executor.execute(() ->{
            sender.send(simpleMailMessage);
            System.out.println("发送成功");
        });

    }
}
